/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelModem.java
 *
 * Created on 31/01/2012, 14:10:00
 */

package tsb.UI.Paneles;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import tsb.UI.Paneles.PC.PanelFastEthernetRJ45;
import tsb.dominio.interfaces.InterfaceDeConeccion;
import tsb.dominio.interfaces.InterfazModemPC;

/**
 *
 * @author Fede
 */
public class PanelModem extends javax.swing.JPanel
{

    private boolean pestaña1=false; // para saber si la pestaña ya tiene un panel
    private boolean pestaña2=false; // para saber si la pestaña ya tiene un panel
    ImageIcon[] images;
    String[] opciones = {"Si","No"};
    Integer[] intArray;

    public PanelModem()
    {
        images = new ImageIcon[opciones.length];
        intArray = new Integer[opciones.length];
        for (int i = 0; i < opciones.length; i++) {
            intArray[i] = new Integer(i);
            if(i==0)
            {images[i] = new javax.swing.ImageIcon(getClass().getResource("/tsb/UI/Imagenes/PRENDIDO_16X16.png"));
            }
            else
            {images[i] = new javax.swing.ImageIcon(getClass().getResource("/tsb/UI/Imagenes/APAGADO_16X16.png"));
            }
            if (images[i] != null) {
                images[i].setDescription(opciones[i]);
            }
        }
        initComponents();
        ComboBoxRenderer renderer= new ComboBoxRenderer();
        renderer.setPreferredSize(new Dimension(10, 20));
        this.cmbEncendido.setRenderer(renderer);

    }
     public void setNombreAMostrar(String nombre)
    {
        this.txtNombreAMostrar.setText(nombre);
    }

    public String getNombreAMostrar()
    {
        return this.txtNombreAMostrar.getText();
    }

     public void setEncendido(boolean encendido)
    {
        if(encendido)
        {
            this.cmbEncendido.setSelectedIndex(0);
        }
        else
        {
            this.cmbEncendido.setSelectedIndex(1);
        }
    }

    public boolean getEncendido()
    {
        if(this.cmbEncendido.getSelectedIndex()==0)
            return true;
        else
            return false;
    }

     public boolean getPestaña1() {
        return pestaña1;
    }

    public void setPestaña1(boolean pestaña1) {
        this.pestaña1 = pestaña1;
    }

    public boolean getPestaña2() {
        return pestaña2;
    }

    public void setPestaña2(boolean pestaña2) {
        this.pestaña2 = pestaña2;
    }
    public boolean getEthernet()
    {
        if(this.cmbConectado1.getSelectedIndex()==0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    public void setEthernet(boolean aux)
    {
        if(aux==true)
        {
            this.cmbConectado1.setSelectedIndex(0);
        }
        else
        {
            this.cmbConectado1.setSelectedIndex(1);
        }
    }
    public boolean getLineaTelefonica()
    {
        if(this.cmbConectado.getSelectedIndex()==0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    public void setLineaTelefonica(boolean aux)
    {
        if(aux==true)
        {
            this.cmbConectado.setSelectedIndex(0);
        }
        else
        {
            this.cmbConectado.setSelectedIndex(1);
        }
    }
    public void setComboEthernet(boolean aux)
    {
        if(aux==true)
        {
            this.cmbConectado1.setSelectedIndex(0);
        }
        else
        {
            this.cmbConectado1.setSelectedIndex(1);
        }
    }
    public void setComboLineaTelefonica(boolean aux)
    {
        if(aux==true)
        {
            this.cmbConectado.setSelectedIndex(0);
        }
        else
        {
            this.cmbConectado.setSelectedIndex(1);
        }
    }

    

    public void setCampos(InterfazModemPC e)
    {
        if(e.getEstado())
        {
             this.cmbEncendido.setSelectedIndex(0);
        }
        else
        {
            this.cmbEncendido.setSelectedIndex(1);
        }
       
        if(e.getConectadoFE())
        {
            this.cmbConectado.setSelectedIndex(0);
        }
        else
        {
            this.cmbConectado.setSelectedIndex(1);
        }

       
   }
    


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        PestañasConfiguraciones = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        txtNombreAMostrar = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        cmbEncendido = new javax.swing.JComboBox(intArray);
        labelEncendido = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        pestañasInterfaces = new javax.swing.JTabbedPane();
        panelPestaña4 = new javax.swing.JPanel();
        labelConectado1 = new javax.swing.JLabel();
        cmbConectado1 = new javax.swing.JComboBox();
        panelPestaña3 = new javax.swing.JPanel();
        labelConectado = new javax.swing.JLabel();
        cmbConectado = new javax.swing.JComboBox();

        PestañasConfiguraciones.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        txtNombreAMostrar.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel2.setText("Nombre a Mostrar:");

        labelEncendido.setFont(new java.awt.Font("Tahoma", 0, 14));
        labelEncendido.setText("Encendido:");

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Interfaces de Conexión"));

        panelPestaña4.setBackground(new java.awt.Color(255, 255, 255));

        labelConectado1.setFont(new java.awt.Font("Tahoma", 0, 14));
        labelConectado1.setText("Conectado:");

        cmbConectado1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "     SI", "     NO" }));

        org.jdesktop.layout.GroupLayout panelPestaña4Layout = new org.jdesktop.layout.GroupLayout(panelPestaña4);
        panelPestaña4.setLayout(panelPestaña4Layout);
        panelPestaña4Layout.setHorizontalGroup(
            panelPestaña4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panelPestaña4Layout.createSequentialGroup()
                .addContainerGap()
                .add(panelPestaña4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(panelPestaña4Layout.createSequentialGroup()
                        .add(119, 119, 119)
                        .add(cmbConectado1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 69, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(labelConectado1))
                .addContainerGap(145, Short.MAX_VALUE))
        );
        panelPestaña4Layout.setVerticalGroup(
            panelPestaña4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panelPestaña4Layout.createSequentialGroup()
                .addContainerGap()
                .add(panelPestaña4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(labelConectado1)
                    .add(cmbConectado1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(126, Short.MAX_VALUE))
        );

        pestañasInterfaces.addTab("Fast Ethernet", panelPestaña4);

        panelPestaña3.setBackground(new java.awt.Color(255, 255, 255));

        labelConectado.setFont(new java.awt.Font("Tahoma", 0, 14));
        labelConectado.setText("Conectado:");

        cmbConectado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "     SI", "     NO" }));

        org.jdesktop.layout.GroupLayout panelPestaña3Layout = new org.jdesktop.layout.GroupLayout(panelPestaña3);
        panelPestaña3.setLayout(panelPestaña3Layout);
        panelPestaña3Layout.setHorizontalGroup(
            panelPestaña3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panelPestaña3Layout.createSequentialGroup()
                .addContainerGap()
                .add(panelPestaña3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(panelPestaña3Layout.createSequentialGroup()
                        .add(119, 119, 119)
                        .add(cmbConectado, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 69, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(labelConectado))
                .addContainerGap(145, Short.MAX_VALUE))
        );
        panelPestaña3Layout.setVerticalGroup(
            panelPestaña3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panelPestaña3Layout.createSequentialGroup()
                .addContainerGap()
                .add(panelPestaña3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(labelConectado)
                    .add(cmbConectado, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(126, Short.MAX_VALUE))
        );

        pestañasInterfaces.addTab("Linea Telefonica", panelPestaña3);

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(pestañasInterfaces, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(pestañasInterfaces, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 185, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jLabel2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(txtNombreAMostrar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
                        .add(100, 100, 100))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(labelEncendido)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(119, 119, 119)
                                .add(cmbEncendido, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 69, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(172, Short.MAX_VALUE))))
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(26, 26, 26)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(txtNombreAMostrar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(labelEncendido)
                    .add(cmbEncendido, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 8, Short.MAX_VALUE)
                .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        PestañasConfiguraciones.addTab("Configuraciones", jPanel1);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PestañasConfiguraciones, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PestañasConfiguraciones, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTabbedPane PestañasConfiguraciones;
    private javax.swing.JComboBox cmbConectado;
    private javax.swing.JComboBox cmbConectado1;
    private javax.swing.JComboBox cmbEncendido;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JLabel labelConectado;
    private javax.swing.JLabel labelConectado1;
    private javax.swing.JLabel labelEncendido;
    private javax.swing.JPanel panelPestaña3;
    private javax.swing.JPanel panelPestaña4;
    private javax.swing.JTabbedPane pestañasInterfaces;
    private javax.swing.JTextField txtNombreAMostrar;
    // End of variables declaration//GEN-END:variables
      class ComboBoxRenderer extends JLabel
                           implements ListCellRenderer {
        private Font uhOhFont;
 
        public ComboBoxRenderer() {
            setOpaque(true);
            setHorizontalAlignment(CENTER);
            setVerticalAlignment(CENTER);
        }
 
        /*
         * This method finds the image and text corresponding
         * to the selected value and returns the label, set up
         * to display the text and image.
         */
        public Component getListCellRendererComponent(
                                           JList list,
                                           Object value,
                                           int index,
                                           boolean isSelected,
                                           boolean cellHasFocus) {
            //Get the selected index. (The index param isn't
            //always valid, so just use the value.)
            int selectedIndex = ((Integer)value).intValue();
 
            if (isSelected) {
                setBackground(list.getSelectionBackground());
                setForeground(list.getSelectionForeground());
            } else {
                setBackground(list.getBackground());
                setForeground(list.getForeground());
            }
 
            //Set the icon and text.  If icon was null, say so.
            ImageIcon icon = images[selectedIndex];
            String pet = opciones[selectedIndex];
            setIcon(icon);
            if (icon != null) {
                setText(pet);
                setFont(list.getFont());
            } else {
                setUhOhText(pet + " (no image available)",
                            list.getFont());
            }
 
            return this;
        }
 
        //Set the font and text when no image was found.
        protected void setUhOhText(String uhOhText, Font normalFont) {
            if (uhOhFont == null) { //lazily create this font
                uhOhFont = normalFont.deriveFont(Font.ITALIC);
            }
            setFont(uhOhFont);
            setText(uhOhText);
        }
    }



}

